package net.fonline.apps;

import javax.microedition.lcdui.Graphics;
import net.fonline.apps.pathfinder.ArrayList;

/**
 * This is the gameworld of LineTowerWars.
 * Contains all map tiles (entities) and monsters.
 * @author Michael
 */
public class MapManager {

    EchoCanvas ec;
    public Entity[][] entities;
    MonsterList monsters;
    public static final int x_dim = 9;
    public static final int y_dim = 20;
    public ArrayList current_path = null;

    public void resetPath() {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                this.entities[i][j].resetPath();
            }
        }
    }

    public MapManager(EchoCanvas ec) {
        this.ec = ec;
        this.entities = new Entity[x_dim][y_dim];
        for (int i = 0; i < x_dim; i++) {
            for (int j = 0; j < y_dim; j++) {
                this.entities[i][j] = new Entity(ec, i * 20, j * 20, 19, 19, false);
            }
        }
        this.monsters = new MonsterList();
    }

    public void move(double time) {
        for (int i = 0; i < x_dim; i++) {
            for (int j = 0; j < y_dim; j++) {
                this.entities[i][j].move(time);
            }
        }
        //only move if there is currently no cheat
        if (!ec.cheatbot.cheat) {
            this.monsters.move(time);
        }
    }

    public void update(Graphics g) {
        for (int i = 0; i < x_dim; i++) {
            for (int j = 0; j < y_dim; j++) {
                this.entities[i][j].update(g);
            }
        }
        this.monsters.update(g);
    }
}